using System.Linq;
using Sustainalytics.ESG.Entities;
using Sustainalytics.Synchronization.Validation.ValidationRules.Common;

namespace Sustainalytics.Synchronization.Validation.ValidationRules.Comprehensive
{
    public class KeyESGIssuesRule : ComprehensiveRule<CompanyKeyESGIssue>
    {
        public override Severity Severity => Severity.Yellow;
        public override BusinessResearchProduct BusinessResearchProduct => BusinessResearchProduct.Comprehensive;
        public override string Code => "YR20";
        public override string InformationalMessage => "At least 2 key issue fields must have text";

        public KeyESGIssuesRule()
        {
            For(x => x.KeyESGIssues)
                .When(
                    (validatedEntity, referenceEntity) =>
                    validatedEntity.KeyESGIssues != null && validatedEntity.KeyESGIssues.Count >= 2
                   && validatedEntity.KeyESGIssues.Count(x => !string.IsNullOrEmpty(x.Comment)) >= 2)
                .WithKey(x => x.Id)
                .WithMessage("The company {0} #{1}# does not have compliant KEI issues comments");
        }
    }
}